from asyncio.windows_events import NULL

from flask import Blueprint, request, jsonify
from sqlalchemy import null

from service.commentService import *
from service import commentService

comment_bp = Blueprint('comment_bp', __name__)


@comment_bp.route('/<id>', methods=['GET'])
def get_comments(id):
    return commentService.get_comments(id)


@comment_bp.route('/', methods=['POST'])
def create_comment():
    data = request.get_json()
    if 'score' in data:
        comment = Comment(data['book_id'], data['name'], data['content'], data['score'], data['picture'])
    else:
        comment = Comment(data['book_id'], data['name'], data['content'], -1.0, data['picture'])
    return commentService.creat_comments(comment)


@comment_bp.route('/<id>', methods=['POST'])
def delete_comment(id):
    return commentService.delete_comment(id)
